package viewmodel;


import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Path;
import org.zkoss.zk.ui.Session;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.*;
 

public class IndexViewModel {

	Menu message;
	private Session s ;
	@Init
	public void init()
	{
		
// 		設定使用者login資訊
//		s = Sessions.getCurrent();
//		s.setAttribute("memberID", "1@gmail.com");
//		s.setAttribute("memberName", "李小華");	
	}
	
	@Command
	public void goToMemberMgt(@BindingParam("S") String s)
	{
		
			Include include = (Include) Path.getComponent("/win/iPage"); 
			include.setSrc("/page/"+s+".zul");
			
				
	}
	@Command
	public void dealWithMessage(){
		//聊天通道從這方法進入
		s = Sessions.getCurrent();
		new messageViewModel((String)s.getAttribute("memberID"));
	}
	
	
	@Command
	public void showLoginModal() {
	   Window window = (Window)Executions.createComponents(
	           "/page/LoginPage.zul", null, null);
	   window.doModal();
	}
	
	@Command
	public void logout()
	{
		s = Sessions.getCurrent();
		s.removeAttribute("memberID");
		s.removeAttribute("memberName");
		s.removeAttribute("memberPic");
		
		Executions.sendRedirect("/index.zul");
	}
	
}
